package com.kirayous.api.blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kirayous.common.dto.UniqueViewDTO;
import com.kirayous.common.entity.UniqueView;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author KiraYous
 * @since 2021-09-29
 */
@Mapper
public interface UniqueViewMapper extends BaseMapper<UniqueView> {




    /**
     * 获取7天用户量
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 用户量
     */
    @Select("        SELECT\n" +
            "        DATE_FORMAT( create_time, \"%Y-%m-%d\" ) as `day`,\n" +
            "        views_count\n" +
            "        FROM\n" +
            "        `tb_unique_view`\n" +
            "        WHERE\n" +
            "        create_time > #{startTime}\n" +
            "        AND create_time <=  #{endTime}\n" +
            "        ORDER BY\n" +
            "        create_time")
    List<UniqueViewDTO> listUniqueViews(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
}
